package com.magenta.maxoptra.gis;

import static com.magenta.maxoptra.gis.GISFieldType.INTEGER;
import static com.magenta.maxoptra.gis.GISFieldType.TEXT;


/**
 * User: KuznetsovD
 * Date: 25.10.11
 * Time: 16:14
 */
public enum OsrmMapAttribute implements GISAccountProperty {

    OsrmRoutingUrl(GisParameter.routing_url, MapProviderType.osrm, TEXT, "http://127.0.0.1:5000/tdmatrix?loc={0},{1}&loc={2},{3}", true, 1L, true),
    OsrmRoutingPathUrl(GisParameter.routing_path_url, MapProviderType.osrm, TEXT, "http://127.0.0.1:5000/viaroute?loc={0},{1}&loc={2},{3}", true, 1L, true),
    OsrmRoutingMatrixUrl(GisParameter.routing_matrix_url, MapProviderType.osrm, TEXT, "http://127.0.0.1:5000/matrix?", true, 1L, true),
    OsrmPointLocatorUrl(GisParameter.point_locator_url, MapProviderType.osrm, TEXT, "http://127.0.0.1:5000/locate?loc={0},{1}&z={2}", true, 1L, true),
    OsrmEnableCache(GisParameter.enableCache, MapProviderType.osrm, GISFieldType.BOOLEAN, "true", true, 2L, true),
    OsrmCacheStorageTime(GisParameter.cacheStorageTime, MapProviderType.osrm, GISFieldType.INTEGER, "30", true, 3L, true),
    OsrmRoutesBatchSizeForDistanceCalculation(GisParameter.routes_batch_size_for_distance_calculation, MapProviderType.osrm, GISFieldType.INTEGER, "30", true, 4L, true),
    OsrmPersistedCacheMessageSize(GisParameter.persisted_cache_message_size, MapProviderType.osrm, INTEGER, "100", true, 5L, true),
    OsrmAttemptsCountForBatchDistanceCalculation(GisParameter.attempts_count_for_batch_distance_calculation, MapProviderType.osrm, INTEGER, "3", false, 6L, true),
    OsrmEnableLog(GisParameter.enableLogging, MapProviderType.osrm, GISFieldType.BOOLEAN, "false", false, 6L, true, false),
    OsrmCorrectionFactor(GisParameter.correctionFactor, MapProviderType.osrm, GISFieldType.FLOAT, "1", true, 7L, false, false);

    private String name;
    private String label;
    private String tab = "GIS";
    private Long order;
    private GISFieldType type;
    private String defaultValue;
    private boolean required;
    private String groupName;
    private boolean important = true;
    private boolean readOnly = false;

    public boolean isImportant() {
        return important;
    }

    public String getName() {
        return name;
    }

    public GISFieldType getType() {
        return type;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public Boolean getMandatory() {
        return required;
    }

    public String getGroup() {
        return groupName;
    }

    public String getLabel() {
        return label;
    }

    public Long getOrder() {
        return order;
    }

    public String getTab() {
        return tab;
    }

    private OsrmMapAttribute(String name, String label, GISFieldType type, String defaultValue,
                             boolean required, String groupName, Long order, boolean important, boolean readOnly) {
        this(name, label, type, defaultValue, required, groupName, order, important);
        this.readOnly = readOnly;
    }


    private OsrmMapAttribute(String name, String label, GISFieldType type, String defaultValue,
                             boolean required, String groupName, Long order, boolean important) {
        this.name = name;
        this.label = label;
        this.type = type;
        this.defaultValue = defaultValue;
        this.groupName = groupName;
        this.required = required;
        this.order = order;
        this.important = important;
    }

    private OsrmMapAttribute(GisParameter parameter, MapProviderType providerType, GISFieldType type,
                             String defaultValue, boolean required, Long order, boolean important, boolean readOnly) {
        this(parameter, providerType, type, defaultValue, required, order, important);
        this.readOnly = readOnly;
    }


    private OsrmMapAttribute(GisParameter parameter, MapProviderType providerType, GISFieldType type,
                             String defaultValue, boolean required, Long order, boolean important) {
        this(parameter.withProvider(providerType.name()),
                parameter.getLabel(),
                type,
                defaultValue,
                required,
                providerType.getLabel(),
                order, important);
    }

    public boolean isReadOnly() {
        return readOnly;
    }

}
